package com.java.service.impl;

import com.java.bean.Item;
import com.java.dao.ItemDao;
import com.java.service.ItemService;
import com.java.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemServiceImpl implements ItemService{

    @Autowired
    private  ItemDao itemDao;

    @Override
    public PageInfo<Item> findItemByCondition(String name, Integer page, Integer size) {
        //1.查询数据总条数
        Integer count = itemDao.findCountByNameLike(name);
        //2.创建分页工具类
        PageInfo<Item> pageInfo=new PageInfo(page,size,count);
        //3.插叙list
        List<Item> list = itemDao.findByNameLikeLimit(name,pageInfo.getOffset(),pageInfo.getSize());
        //4.将查询到的数据封装到pageonfo
        pageInfo.setList(list);
         //5.返回 pageinfo
        return pageInfo;
    }

    @Override
    public Integer save(Item item) {
        Integer count = itemDao.save(item);
        return count;
    }

    @Override
    public Integer deleteById(Integer id) {
        Integer count = itemDao.deleteById(id);
        return count;
    }

    @Override
    public Item findById(Integer id) {
        Item item = itemDao.findById(id);
        return item;
    }

    @Override
    public Integer updateById(Item item) {
        Integer count = itemDao.updateById(item);
        return count;
    }
}
